package org.unt.db;

public class Column {

	public final static String CHAR = "CHAR";
	public final static String DECIMAL = "DECIMAL";
	public final static String SMALLINT = "SMALLINT";
	public final static String TIMESTAMP = "TIMESTAMP";
	public final static String DATE = "DATE";

	private String name;
	private String type;
	private int length;
	private int scale;
	private boolean nullable;

	public Column(String name, String type, int length, int scale,
			boolean nullable) {
		super();
		this.name = name;
		this.type = type;
		this.length = length;
		this.nullable = nullable;
		this.scale = scale;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public boolean isNullable() {
		return nullable;
	}

	public void setNullable(boolean nullable) {
		this.nullable = nullable;
	}

	public int getScale() {
		return scale;
	}

	public void setScale(int scale) {
		this.scale = scale;
	}

	public String toString() {

		String nameStr = name;

		if (nameStr.length() < 8) {
			nameStr = nameStr + "\t\t\t";
		} else if (nameStr.length() < 16) {
			nameStr = nameStr + "\t\t";
		} else if (nameStr.length() < 24) {
			nameStr = nameStr + "\t";
		} else {
			nameStr = nameStr.substring(0, 23) + " ";
		}

		return nameStr + type + "\t" + length + "\t" + scale + "\t" + nullable;
	}

	public boolean compare(Column column, boolean doLengthComparison) {
		return DbLogic.compareColumns(this, column, doLengthComparison);
	}
}
